﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<Mvcmediaplayer.Models.Video>>" %>
<%@ Import Namespace="Mvcmediaplayer.Models" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Video Manager
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript">
    $(document).ready(function () {
        var pgindex = $('#pageIndex');
        pgindex.val(0);
        $('.nav').click(function () {
            if ($(this).attr('id') == 'prev') {
                if (parseInt($('#pageIndex').val()) == 0)
                { return; }
                else {
                    pgindex.val(parseInt(pgindex.val()) - 1);
                }
            }
            if ($(this).attr('id') == 'next') {
                if (parseInt($('#pageIndex').val()) ==( parseInt($('#pageCount').val())-1)) {
                    return;
                }
                else {
                    pgindex.val(parseInt(pgindex.val()) + 1);
                }
            }
            $('#loader').html('Loading....').css('background-color', 'yellow').css('width', '50');
            $.ajax({ type: 'POST', url: 'VideoManager/getdata', data: { pageIndex: $('#pageIndex').val() }, success: function (data) { $('#empTable tbody').html(data); $('#loader').html('').css('background-color','white'); } });
        });
    });
</script>

	<h2>Videos</h2>
	<input type="hidden" id="pageIndex" value="0"/>
	<input type="hidden" id="pageCount" value='<%=(Math.Ceiling(new mediaEntities().Videos.Count()/5.0)) %>' />
	   <div id="loader"  style="color:Red;width:20;text-align:center;vertical-align:middle;"></div>
	<table border="1" id="empTable" style="cursor:default">
	<tr>
	<th>Title</th>
	<th>Review</th>
	<th>Year</th>
	<th></th>
	<th></th>
	</tr>
	<% foreach (var item in Model) {  %>
	<tr>
	<td><%:item.Title %></td>
	<td><%:item.Review %></td>
	<td><%:item.Year %></td>
	<td><%:Html.ActionLink("Edit", "Edit", new { id=item.Id})%></td>
	  <td><%:Html.ActionLink("Delete", "Delete", new { id=item.Id})%></td>
	</tr>
	<%} %>
	</table>
	<div id="pager" class="pager">
	<br />
		<img src="../../images/prev.ico" id="prev" class="nav" />
		<img src="../../images/next.ico" id="next" class="nav" />     
	</div>
</asp:Content>

